package testdomainmedicine;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import conditionsAPI.AndDomainCondition;
import conditionsAPI.ConditionDuplicatedException;
import conditionsAPI.ConditionsConfiguration;
import conditionsAPI.NotDomainCondition;

public class TestDomainMedicine {

	private BloodTestCondition bloodTestCondition;
	private UrineTestCondition urineTestCondition;
	private BloodDonationCondition bloodDonationCondition;
	
	private NotDomainCondition notBloodDonationCondition;
	private AndDomainCondition andCondition;
	
	@Before
	public void setUp(){
		try {
			this.bloodTestCondition = new BloodTestCondition("bloodTest");
			this.urineTestCondition = new UrineTestCondition("urineTest");
			this.bloodDonationCondition = new BloodDonationCondition("bloodDonation");
			
			this.andCondition = new AndDomainCondition("and");
			this.notBloodDonationCondition = new NotDomainCondition(this.bloodDonationCondition);
			
		} catch (ConditionDuplicatedException e) {
			e.printStackTrace();
		}
		
		this.andCondition.addPreCondition(this.bloodTestCondition);
		this.andCondition.addPreCondition(this.urineTestCondition);
		this.andCondition.addPreCondition(this.notBloodDonationCondition);
		
	}
	
	@After
	public void tearDown(){
		ConditionsConfiguration.reset();
	}
	
	@Test
	public void setTargetAndConditionAllConditionsFulfilledCheckTargetResultEqualsAndCondition(){
		ConditionsConfiguration.setTarget(this.andCondition);
		Collection<Object> medicalPractices = new ArrayList<Object>();
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.URINE_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_TEST));
		
		ConditionsConfiguration.processObjects(medicalPractices);
		
		assertEquals(this.andCondition.getId(),ConditionsConfiguration.getLastConditionFulfilled());
	}
	
	@Test
	public void setTargetAndConditionAllConditionsFulfilledCheckAndConditionIsTrue(){
		ConditionsConfiguration.setTarget(this.andCondition);
		Collection<Object> medicalPractices = new ArrayList<Object>();
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.URINE_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_TEST));
		
		ConditionsConfiguration.processObjects(medicalPractices);
		
		assertTrue(this.andCondition.isTrue());
	}

	@Test
	public void setTargetAndConditionSomeConditionsFulfilledCheckTargetResultIsEmpty(){
		ConditionsConfiguration.setTarget(this.andCondition);
		Collection<Object> medicalPractices = new ArrayList<Object>();
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.URINE_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_DONATION));
		
		ConditionsConfiguration.processObjects(medicalPractices);
		
		assertEquals("",ConditionsConfiguration.getLastConditionFulfilled());
	}
	
	@Test
	public void setTargetAndConditionSomeConditionsFulfilledCheckAndConditionIsFalse(){
		ConditionsConfiguration.setTarget(this.andCondition);
		Collection<Object> medicalPractices = new ArrayList<Object>();
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.URINE_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_TEST));
		medicalPractices.add(new MedicalPractice(MedicalPractice.Description.BLOOD_DONATION));
		
		ConditionsConfiguration.processObjects(medicalPractices);
		
		assertFalse(this.andCondition.isTrue());
	}
	
}
